#include "Base.h"
#include "ManagerClientPlayer.h"
#include "BaseProtocol.h"

CManagerClientPlayer::CManagerClientPlayer(void)
{
	strcpy(m_szAdminPassword, "admin");
	m_bRetryCount = 0;
}

CManagerClientPlayer::~CManagerClientPlayer(void)
{
}

Msg* CManagerClientPlayer::CreateMsg(DWORD dwMsgId, int nLen)
{
	switch(dwMsgId)
	{
	case Msg_Req_Admin_Login:
		{
			return new ReqAdminLogin;
		}
		break;
	}
	return NULL;
}

BOOL CManagerClientPlayer::OnMsg(Msg *pMsg)
{
	DWORD dwMsgId = pMsg->GetMsgId();
	switch(dwMsgId)
	{
	case Msg_Req_Admin_Login:
		{
			return OnAdminLogin(pMsg);
		}
	default:
		break;
	}
	return FALSE;
}

BOOL CManagerClientPlayer::OnAdminLogin(Msg *pMsg)
{
	ReqAdminLogin *pReqLogin = (ReqAdminLogin *)pMsg;

	AckAdminLogin ack;
	ack.m_bSuccess = TRUE;
	if(strcmp(pReqLogin->m_szPassword, m_szAdminPassword))
	{
		ack.m_bSuccess = FALSE;
		m_bRetryCount++;
	}
    SendMsg(&ack);

	if(m_bRetryCount >= 3)
	{
		return FALSE;
	}
	return TRUE;
}